package org.flower.web.servlet;

import org.flower.dao.CommodityClassDao;
import org.flower.dao.impl.CommodityClassDaoImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 删除商品类servlet
 *
 * @author Aizen
 * @date 2021/12/23
 */
@WebServlet("/manager/deleteCommodityClassServlet.shtml")
public class DeleteCommodityClassServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        CommodityClassDao classDao = new CommodityClassDaoImpl();
        boolean b = classDao.deleteCommodityClassById(Integer.parseInt(id));
        PrintWriter writer=response.getWriter();
        if(b){
            writer.write(
                    "<script type=\"text/javascript\">alert('删除成功！');setInterval(\"\",10);parent.location.href='" +
                            request.getContextPath()
                            + "/manager/commodityClassServlet'</script>");
            writer.flush();
            writer.close();
        }else{
            writer.write(
                    "<script type=\"text/javascript\">alert('删除失败！');setInterval(\"\",10);parent.location.href='" +
                            request.getContextPath()
                            + "/manager/commodityClassServlet'</script>");
            writer.flush();
            writer.close();
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
